/*
 * Copyright 2010 Shumpei Shiraishi
 */
package net.fivegoods.entity.impl.slim3;


@javax.ws.rs.Path("/volunteers")
@org.slim3.datastore.Model
@javax.persistence.Entity
@javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.NONE)
@javax.xml.bind.annotation.XmlRootElement
@javax.annotation.Generated("momo.annotation.processing.MomoProcessor")
public class VolunteerModel implements java.io.Serializable {
	private static final long serialVersionUID = 1L;
	
	@com.google.inject.Inject
	static javax.validation.Validator validator;
	
	@javax.ws.rs.Path("/{key}")
	@javax.ws.rs.GET
	public static net.fivegoods.entity.impl.slim3.VolunteerModel getByKeyString(
		@javax.ws.rs.PathParam("key") java.lang.String keyStr) {
		return getByKey(com.google.appengine.api.datastore.KeyFactory.stringToKey(keyStr));
	}
	
	public static net.fivegoods.entity.impl.slim3.VolunteerModel getByKey(com.google.appengine.api.datastore.Key key) {
		return org.slim3.datastore.Datastore.getOrNull(net.fivegoods.entity.impl.slim3.VolunteerModel.class, key);
	}
	@javax.ws.rs.Path("/{key}")
	@javax.ws.rs.DELETE
	public static void deleteByKeyString(
		@javax.ws.rs.PathParam("key") java.lang.String keyStr) {
		deleteByKey(com.google.appengine.api.datastore.KeyFactory.stringToKey(keyStr));
	}
	public static void deleteByKey(com.google.appengine.api.datastore.Key key) {
		org.slim3.datastore.Datastore.delete(key);
	}


	@javax.ws.rs.GET
	public static java.util.List<net.fivegoods.entity.impl.slim3.VolunteerModel> query(
		@javax.ws.rs.QueryParam("name") java.lang.String name,
		@javax.ws.rs.DefaultValue("EQUAL") @javax.ws.rs.QueryParam("nameOp") java.lang.String nameOp,
		@javax.ws.rs.QueryParam("guid") java.lang.String guid,
		@javax.ws.rs.DefaultValue("EQUAL") @javax.ws.rs.QueryParam("guidOp") java.lang.String guidOp,
		@javax.ws.rs.QueryParam("sort") java.util.List<momo.slim3.SortParam> sortParams) {
		org.slim3.datastore.ModelQuery<VolunteerModel> _query_ = org.slim3.datastore.Datastore.query(VolunteerModel.class);
		if (nameOp.equals("IS_NULL")) {
			_query_.filter("name", com.google.appengine.api.datastore.Query.FilterOperator.EQUAL, null);
		} else if (name != null) {
			_query_.filter("name", com.google.appengine.api.datastore.Query.FilterOperator.valueOf(nameOp), name);
		}
		if (guidOp.equals("IS_NULL")) {
			_query_.filter("guid", com.google.appengine.api.datastore.Query.FilterOperator.EQUAL, null);
		} else if (guid != null) {
			_query_.filter("guid", com.google.appengine.api.datastore.Query.FilterOperator.valueOf(guidOp), guid);
		}
		for (momo.slim3.SortParam _sort_ : sortParams) {
			_query_.sort(_sort_.getProperty(),
				_sort_.isAsc() ?
					com.google.appengine.api.datastore.Query.SortDirection.ASCENDING :
					com.google.appengine.api.datastore.Query.SortDirection.DESCENDING);
		}
		return _query_.asList();
	}

	public VolunteerModel() {
	}

	@org.slim3.datastore.Attribute(primaryKey = true)
	private com.google.appengine.api.datastore.Key key;

	public com.google.appengine.api.datastore.Key getKey() {
		return key;
	}
	@javax.xml.bind.annotation.XmlElement
	public java.lang.String getKeyString() {
		return com.google.appengine.api.datastore.KeyFactory.keyToString(key);
	}
	public void setKey(com.google.appengine.api.datastore.Key key) {
		this.key = key;
	}




	@org.slim3.datastore.Attribute	
@javax.ws.rs.FormParam("name")
	private java.lang.String name;
	
	public void setName(java.lang.String name) {
		this.name = name;
	}
	@javax.xml.bind.annotation.XmlElement
	public java.lang.String getName() {
		return this.name;
	}

	@org.slim3.datastore.Attribute	
@javax.ws.rs.FormParam("guid")
	private java.lang.String guid;
	
	public void setGuid(java.lang.String guid) {
		this.guid = guid;
	}
	@javax.xml.bind.annotation.XmlElement
	public java.lang.String getGuid() {
		return this.guid;
	}

	@org.slim3.datastore.Attribute(persistent=false)
	private final org.slim3.datastore.InverseModelListRef<net.fivegoods.entity.impl.slim3.MissionExecutionModel, net.fivegoods.entity.impl.slim3.VolunteerModel> missionsRef =
		new org.slim3.datastore.InverseModelListRef<net.fivegoods.entity.impl.slim3.MissionExecutionModel, net.fivegoods.entity.impl.slim3.VolunteerModel>(net.fivegoods.entity.impl.slim3.MissionExecutionModel.class, "volunteerRef", this);

	public org.slim3.datastore.InverseModelListRef<net.fivegoods.entity.impl.slim3.MissionExecutionModel, net.fivegoods.entity.impl.slim3.VolunteerModel> getMissionsRef() {
		return this.missionsRef;
	}


	@javax.ws.rs.POST
	public void save() {
		if (this.key != null) {
			throw new java.lang.IllegalStateException("key is not null.");
		}
		if (this.validator != null) {
			java.util.Set<javax.validation.ConstraintViolation<VolunteerModel>> violations = validator.validate(this);
			if (!violations.isEmpty()) {
				throw new javax.validation.ConstraintViolationException(new java.util.HashSet<javax.validation.ConstraintViolation<?>>(violations));
			}
		}
		org.slim3.datastore.Datastore.put(this);
	}
	@javax.ws.rs.Path("/{key}")
	@javax.ws.rs.PUT
	public void save(@javax.ws.rs.PathParam("key") java.lang.String keyStr) {
		this.key = com.google.appengine.api.datastore.KeyFactory.stringToKey(keyStr);
		if (this.validator != null) {
			java.util.Set<javax.validation.ConstraintViolation<VolunteerModel>> violations = validator.validate(this);
			if (!violations.isEmpty()) {
				throw new javax.validation.ConstraintViolationException(new java.util.HashSet<javax.validation.ConstraintViolation<?>>(violations));
			}
		}
		org.slim3.datastore.Datastore.put(this);
	}
	
	public void delete() {
		if (this.key != null) {
			deleteByKey(this.key);
		}
	}
}
